#!/bin/bash -e

function info() {
echo Usage: `basename $0` '[-s name -i interval -b 37] methy_ratio fields'
exit 2
}

while getopts  ":p:f:b:" opt; do
	case  $opt  in
		p) out_prefix=$OPTARG;;
		f) suffix=$OPTARG;;
        s) sample_name=$OPTARG;;
        i) interval=$OPTARG;;
        b) asemmbly=$OPTARG;;
		*) info;;
	esac
done
shift $(($OPTIND - 1))


if [ $# -lt 1 ]; then info; fi

. $var

cut -f$2 $1|sed 1d > $out_prefix.methy.txt
cat $out_prefix.methy.txt |awk '{print $0 "\tT"}' > $out_prefix.methyl.txt

echo convert tab-delimited methylation result to vcf
# bcftools convert -c CHROM,POS,AA -f$ref_genome  --tsv2vcf $1 -Ov -o $out_prefix.convert.vcf -s$sample_name -R$interval

bcftools convert -c CHROM,POS,AA -f$ref_genome --tsv2vcf $out_prefix.methyl.txt -Ov -o $out_prefix.convert.vcf -s$sample_name

grep '^#' $out_prefix.convert.vcf > $out_prefix.header
sortByRef.pl $out_prefix.convert.vcf $data_path/ref/b37/b37.fa.fai |cat $out_prefix.header - >  $out_prefix.convert.sort.vcf && rm $out_prefix.header $out_prefix.convert.vcf && mv $out_prefix.convert.sort.vcf $out_prefix.convert.vcf


. $cmd_done